home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 3.iso / dist / fw_qt3.idb / usr / freeware / Qt / examples / tux / tux.cpp.z / tux.cpp
C/C++ Source or Header  |  2002-04-08  |  1KB  |  74 lines

  1. #include <qapplication.h>
  2. #include <qwidget.h>
  3. #include <qimage.h>
  4. #include <qpixmap.h>
  5. #include <qbitmap.h>
  6. #include <qfile.h>
  7.  
  8. #include <stdlib.h>
  9.  
  10. class MoveMe : public QWidget
  11. {
  12. public:
  13.     MoveMe( QWidget *parent=0, const char *name=0, WFlags f = 0)
  14.     :QWidget(parent,name, f) {}
  15.  
  16. protected:
  17.     void mousePressEvent( QMouseEvent *);
  18.     void mouseMoveEvent( QMouseEvent *);
  19. private:
  20.     QPoint clickPos;
  21. };
  22.  
  23. void MoveMe::mousePressEvent( QMouseEvent *e )
  24. {
  25.     //    if ( e->button() == LeftButton )
  26.     clickPos = e->pos();
  27. }
  28.  
  29. void MoveMe::mouseMoveEvent( QMouseEvent *e )
  30. {
  31.     //    if ( e->state() & LeftButton )
  32.     move( e->globalPos() - clickPos );
  33. }
  34.  
  35.  
  36.  
  37. int main( int argc, char **argv )
  38. {
  39.     QApplication a( argc, argv );
  40.  
  41.     QString fn="tux.png";
  42.  
  43.     if ( argc >= 2 )
  44.     fn = argv[1];
  45.  
  46.     if ( ! QFile::exists( fn ) )
  47.     exit( 1 );
  48.  
  49.     QImage img( fn );
  50.     QPixmap p;
  51.     p.convertFromImage( img );
  52.     if ( !p.mask() )
  53.     if ( img.hasAlphaBuffer() ) {
  54.         QBitmap bm;
  55.         bm = img.createAlphaMask();
  56.         p.setMask( bm );
  57.     } else {
  58.         QBitmap bm;
  59.         bm = img.createHeuristicMask();
  60.         p.setMask( bm );
  61.     }
  62.     MoveMe w(0,0,Qt::WStyle_Customize|Qt::WStyle_NoBorder);
  63.     w.setBackgroundPixmap( p );
  64.     w.setFixedSize( p.size() );
  65.     if ( p.mask() )
  66.     w.setMask( *p.mask() );
  67.     w.show();
  68.     a.setMainWidget(&w);
  69.  
  70.  
  71.     return a.exec();
  72.  
  73. }
  74.